PROJM =  chan_datacard.so
PROJS =  chan_datacards.so

chan_datacardm_so_OBJS =  app.o at_command.o at_parse.o at_queue.o at_read.o at_response.o \
	chan_datacard.o channel.o char_conv.o cli.o helpers.o manager.o \
	memmem.o ringbuffer.o cpvt.o dc_config.o pdu.o mixbuffer.o pdiscovery.o

chan_datacards_so_OBJS = single.o

test1_OBJS = test/test1.o ringbuffer.o mixbuffer.o
parse_OBJS = test/parse.o at_parse.o char_conv.o pdu.o
discovery_OBJS = tools/discovery.o tools/tty.o

SOURCES = app.c at_command.c at_parse.c at_queue.c at_read.c at_response.c \
	chan_datacard.c channel.c char_conv.c cli.c cpvt.c dc_config.c helpers.c \
	manager.c memmem.c ringbuffer.c single.c pdu.c mixbuffer.c pdiscovery.c

test_SOURCES = test/test1.c test/parse.c
tools_SOURCES = tools/discovery.c tools/tty.c

HEADERS = app.h at_command.h at_parse.h at_queue.h at_read.h at_response.h \
	chan_datacard.h channel.h char_conv.h cli.h cpvt.h dc_config.h export.h \
	helpers.h manager.h memmem.h ringbuffer.h pdu.h mixbuffer.h pdiscovery.h \
	mutils.h

tools_HEADERS = tools/tty.h

EXTRA_DIST = BUGS COPYRIGHT.txt LICENSE.txt README.txt TODO.txt INSTALL \
	Makefile.in asteriskforum config.h.in configure.in stamp-h.in etc \
	dist

BUILD_TOOLS = configure config.sub install-sh config.guess

CC = @CC@
LD = @CC@
STRIP = @STRIP@
RM = @RM@ -fr
INSTALL = @INSTALL@
CHMOD = chmod

# -DAST_MODULE=\"$(PROJM)\" -D_THREAD_SAFE
CFLAGS  = @CFLAGS@ -I$(srcdir) @CPPFLAGS@ @DEFS@ @AC_CFLAGS@
LDFLAGS = @LDFLAGS@ 
SOLINK  = @SOLINK@
LIBS    = @LIBS@
DISTNAME= @PACKAGE_TARNAME@-@PACKAGE_VERSION@.r@PACKAGE_REVISION@

srcdir = @srcdir@
VPATH = @srcdir@

all: @TARGET@

install: all
	$(STRIP) $(PROJM)
	$(INSTALL) -m 755 $(PROJM) @DESTDIR@

$(PROJM): $(chan_datacardm_so_OBJS) Makefile
	$(LD) $(LDFLAGS) $(SOLINK) -o $@ $(chan_datacardm_so_OBJS) $(LIBS)

$(PROJS): $(chan_datacards_so_OBJS) Makefile
	$(LD) $(LDFLAGS) $(SOLINK) -o $@ $(chan_datacards_so_OBJS) $(LIBS)
	$(CHMOD) 755 $@
	mv $@ chan_datacard.so

.c.o:
	$(CC) $(CFLAGS) $(MAKE_DEPS) -o $@ -c $<

tests: test/test1 test/parse

test/test1: $(test1_OBJS)
	$(LD) $(LDFLAGS) -o $@ $(test1_OBJS) $(LIBS)

test/parse: $(parse_OBJS)
	$(LD) $(LDFLAGS) -o $@ $(parse_OBJS) $(LIBS)

tools: tools/discovery

tools/discovery: $(discovery_OBJS)
	$(LD) $(LDFLAGS) -o $@ $(discovery_OBJS) $(LIBS)

clean:
	$(RM) $(PROJM) $(PROJS) *.o *.core .*.d autom4te.cache test/test1 test/*.o tools/discovery test/*.o

dist: $(SOURCES) $(HEADERS) $(EXTRA_DIST) $(BUILD_TOOLS)
	@mkdir $(DISTNAME) $(DISTNAME)/test $(DISTNAME)/tools
	@cp -a $(SOURCES) $(HEADERS) $(EXTRA_DIST) $(BUILD_TOOLS) $(DISTNAME)
	@cp -a $(test_SOURCES) $(DISTNAME)/test
	@cp -a $(tools_SOURCES) $(tools_HEADERS) $(DISTNAME)/tools
	tar czf $(DISTNAME).tgz $(DISTNAME) --exclude .svn -h
	@$(RM) $(DISTNAME)

${srcdir}/configure: configure.in
	cd ${srcdir} && autoconf

config.h: stamp-h
stamp-h: config.h.in config.status
	./config.status

Makefile: Makefile.in config.status
	./config.status

config.status: configure
	./config.status --recheck

ifneq ($(wildcard .*.d),)
   include .*.d
endif
